# COMMON

Name := COMMON LIB
Program := common.a
Include := -I. 
LIBS :=-lpthread -lrt
CPP := g++
CC  := g++
MACRO_DEFINE :=
CPPFLAGS  := -g -Wall  $(Include) $(INCLUDE_FLAG) $(MACRO_DEFINE) -static
CFLAGS := $(CPPFLAGS) 
RM := rm -f
SRCDIRS := .
SRCEXTS := .cpp
SOURCES := $(foreach d,$(SRCDIRS),$(wildcard $(addprefix $(d)/*,$(SRCEXTS))))
OBJS    := $(foreach x,$(SRCEXTS),$(patsubst %$(x),%.o,$(filter %$(x),$(SOURCES))))
DEPS    := $(patsubst %.o,%.d,$(OBJS))

.PHONY : all objs clean cleanall rebuild show run
all:$(Program)

%.d : %.c
	@echo D... $<
	@$(CC) -MM -MD $(CFLAGS) $<
%.d : %.C
	@echo D... $<
	@$(CC) -MM -MD $(CFLAGS) $<
%.d : %.cpp
	@echo D... $<
	@$(CC) -MM -MD $(CPPFLAGS) $<
%.d : %.CPP
	@echo D... $<
	@$(CC) -MM -MD $(CPPFLAGS) $<


objs:$(OBJS)
%.o : %.c
	@echo Compiling... $<
	@$(CC) -c $(CFLAGS) $<
%.o : %.C
	@echo Compiling... $<
	@$(CC) -c $(CFLAGS) $<
%.o : %.cpp
	@echo Compiling... $<
	@$(CPP) -c $(CPPFLAGS) $<
%.o : %.CPP
	@echo Compiling... $<
	@$(CPP) -c $(CPPFLAGS) $<

$(Program) : $(OBJS)
	@echo link... $(Program)
ifeq ($(strip $(SRCEXTS)), .c) 
	@$(CC) -o $(Program) $(OBJS) $(LDFLAGS) $(LINKOPTS) $(LIBS)
else                           
	@$(CPP) -o $(Program) $(OBJS) $(LDFLAGS) $(LINKOPTS) $(LIBS)
endif
	@echo Make $(Name) OK! Execute Name:$(Program)
-include $(DEPS)

clean:
	@$(RM) *.o *.log
cleanall:clean
	@$(RM) $(Program) $(Program).exe $(Program) *.d
rebuild:clean all

run:
	@./$(Program)

show:
	@echo $(SOURCES)
	@echo $(OBJS)
	@echo $(DEPS)
	@echo $(LIB)
	@echo $(Include)
	@echo $(CPPFLAGS)
